<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>首页</title>
</head>
<body>
<h1>首页</h1>
<form th:action="@{/testRequestBody}" method="post" target="_blank">
    <input type="text" name="username" value="刘阿勇">
    <input type="text" name="password" value="lyy123">
    <input type="submit" value="测试@RequestBody">
</form>
<br>
<form th:action="@{/testRequestBody2}" method="post" target="_blank">
    <input type="text" name="username" value="刘阿勇2">
    <input type="text" name="password" value="lyy1232">
    <input type="submit" value="测试@RequestBody">
</form>
<br>
<form th:action="@{/testRequestBody3}" method="post" target="_blank">
    <input type="text" name="username" value="刘阿勇3">
    <input type="text" name="password" value="lyy1233">
    <input type="submit" value="测试@RequestBody">
</form>
<br>

<br>
<hr/>
<br>
<form th:action="@{/testRequestEntity}" method="post" target="_blank">
    <input type="text" name="username" value="刘阿勇">
    <input type="text" name="password" value="lyy123">
    <input type="submit" value="测试RequestEntity">
</form>
<a th:href="@{/testResponse}">通过servletAPI的response对象响应浏览器数据</a><br>
<a th:href="@{/testResponseBody}">通过@ResponseBody响应浏览器数据</a><br>
<a th:href="@{/testResponseUser}">通过@ResponseBody响应浏览器User对象</a><br>
<div id="app">
    <a @click="testAxios" th:href="@{/testAjax}">SpringMVC处理ajax</a><br/>
    <a id="testAxios" th:href="@{/testAxios}">SpringMVC处理ajax2</a><br/>
</div>
<script type="text/javascript" th:src="@{/static/js/vue.js}"></script>
<script type="text/javascript" th:src="@{/static/js/axios.min.js}"></script>
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>

<script type="text/javascript">
    new Vue({
        el: "#app",
        methods: {
            testAxios: function (event) {
                axios({
                    method: "post",
                    url: event.target.href,
                    params: {
                        username: "admin",
                        password: "123456"
                    }
                }).then(function (response) {
                    alert(response.data);
                });
                event.preventDefault();
            }
        }
    });

    $("#testAxios").on("click", function () {
        console.log(this.innerText + ", " + this.href);
        $.ajax({
            type: "POST",
            url: this.href,
            data: {
                username: "admin",
                password: "123456"
            }
        }).then(function (response) {
            console.log(response)
            alert(response);
        });
        ;
        return false;
    })


</script>
</body>
</html>